/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.webservice;

import com.edu.kamai.exception.UserRegisterFailException;
import com.edu.kamai.logic.facade.UserFacade;
import com.edu.kamai.persistence.beans.User;
import java.util.Date;
import java.util.List;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 *
 * @author Administrator
 */
@WebService(serviceName = "userAccountService")
@Stateless()
public class userAccountService {

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "register")
    public Integer register(@WebParam(name = "usrBean")
    User usrBean) throws UserRegisterFailException{
        try{
            return UserFacade.register(usrBean);
        }catch(UserRegisterFailException urfe){
            throw urfe;
        } 
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "register_1")
    @RequestWrapper(className = "com.register_1")
    @ResponseWrapper(className = "com.register_1Response")
    public Integer register(@WebParam(name = "usrID")
    String usrID, @WebParam(name = "usrPwd")
    String usrPwd, @WebParam(name = "usrEmail")
    String usrEmail, @WebParam(name = "role")
    int role) throws UserRegisterFailException{
        User usrBean = new User();
        usrBean.setUserId(usrID);
        usrBean.setPassword(usrPwd);
        usrBean.setEmail(usrEmail);
        //not verified
        usrBean.setStatus(0);
        //student = 1;teacher = 2;
        usrBean.setRole(role);
        usrBean.setRegTime(new Date());
        try{
            return UserFacade.register(usrBean);
        }catch(UserRegisterFailException urfe){
            throw urfe;
        }
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "login")
    public Integer login(@WebParam(name = "usrID")
    String usrID, @WebParam(name = "usrPwd")
    String usrPwd,@WebParam(name="role") int role) {
        int res = UserFacade.login(usrID, usrPwd,role);
        System.out.println("User " + usrID + " login : " + res);
        return res;
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "chekPendingList")
    public List<User> chekPendingList() {
        return UserFacade.chekPendingList();
    }

    /**
     * Web 服务操作
     */
    @WebMethod(operationName = "validateUsr")
    public Integer validateUsr(@WebParam(name = "usrID")
    String usrID) {
        return UserFacade.validateUsr(usrID);
    }
}
